package service

import (
	"go-web/model"
	"go-web/repository"
)

func GetAllUsers() ([]model.User, error) {
	return repository.FindAllUsers()
}

func FindUsersPaged(page, size int) ([]model.User, int64, error) {
	return repository.FindUsersPaged(page, size)
}

func SearchUsers(name, email string, page, size int) ([]model.User, int64, error) {
	return repository.SearchUsers(name, email, page, size)
}

func GetUserByID(id int) (model.User, error) {
	return repository.FindUserByID(id)
}

func AddUser(user *model.User) error {
	return repository.CreateUser(user)
}

func EditUser(id int, input *model.User) (model.User, error) {
	user, err := repository.FindUserByID(id)
	if err != nil {
		return user, err
	}
	user.Name = input.Name
	user.Email = input.Email
	err = repository.UpdateUser(&user)
	return user, err
}

func RemoveUser(id int) error {
	return repository.DeleteUser(id)
}
